package com.lsh.oms.provider.service.order.frozen;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;
import com.lsh.base.common.model.CommonResult;
import com.lsh.oms.api.service.order.frozen.IOrderDeliveryFrozenRestService;
import com.lsh.oms.core.constant.ReturnCode;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * Project Name: lsh-oms
 *
 * @author miaozhuang
 * @date 17/3/27
 * 北京链商电子商务有限公司
 * Package
 * desc:订单发货RestService
 */
@Service(protocol = "rest", timeout = 30000)
@Path("delivery")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({ContentType.APPLICATION_JSON_UTF_8})
@Deprecated
public class OrderDeliveryFrozenRestServiceImpl implements IOrderDeliveryFrozenRestService {

//    private static Logger logger = LoggerFactory.getLogger(OrderDeliveryFrozenRestServiceImpl.class);

//    @Autowired
//    private OrderQueryService orderQueryService;
//
//    @Autowired
//    private OrderDeliveryFrozenService orderDeliveryFrozenService;
//
//    @Value("${shopUrl}")
//    private String shopUrl;

//    @POST
//    @Path("create")
//    @Override
//    public CommonResult<Object> create(OrderDeliveryDTO deliveryDTO) {
//        String logSign = "logSign : " + ToolService.getLogSign();
//        long startTimeMs = System.currentTimeMillis();
//
//        logger.info(logSign + ": 黑狗更新订单状态（发货）入参 －－ " + (deliveryDTO == null ? "" : JsonUtils.obj2Json(deliveryDTO)));
//
//        CommonResult<Object> commonResult = new CommonResult<>();
//
//        try {
//            if(deliveryDTO == null){
//                throw new BusinessException(ReturnCode.REQUEST_PARAMS_IS_NULL,"请求参数不合法，请检验。");
//            }
//
//            if(deliveryDTO.getOrderNo() == null){
//                throw new BusinessException(ReturnCode.REQUEST_PARAMS_IS_NULL,"请求参数不合法，请检验。");
//            }
//
//            OrderHead headDto = orderQueryService.findByCode(deliveryDTO.getOrderNo(), false, false);
//            if (headDto == null) {
//                logger.info(logSign + "请求耗时:" + (startTimeMs - System.currentTimeMillis()) + "ms");
//                throw new BusinessException(ReturnCode.FIND_ORDER_IS_NULL,"用户订单号未查询到订单");
//            }
//
//            if (headDto.getOrderStatus().compareTo(OrderStatus.ORDER_WM_NEW.getIndex()) <= 0) {
//                throw new BusinessException(ReturnCode.ORDER_STATUS_ERROR,"订单状态是" + OrderStatus.getName(headDto.getOrderStatus()) + "，请检验。");
//            }
//
//            int orderStatus = headDto.getOrderStatus().intValue();
//            if (orderStatus < OrderStatus.ORDER_WM_NEW.getIndex() || orderStatus >= OrderStatus.ORDER_DELIVERY.getIndex()) {
//                throw new BusinessException(ReturnCode.REQUEST_FAIL, "发货失败！订单状态为`" + OrderStatus.getName(orderStatus) + "`，请核实！");
//            }
//
//            int ts = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
//            headDto.setUpdateTime(ts);
//
//            OrderShippingHeadDto orderShippingHeadDto = deliveryDTO.getOrderShippingHeadDto();
//            if(orderShippingHeadDto == null || orderShippingHeadDto.getDetails() == null){
//                throw new BusinessException(ReturnCode.FIND_ORDER_IS_NULL,"orderShippingHeadDto 必传");
//            }
//
//            commonResult = orderDeliveryFrozenService.createShippingOrder(deliveryDTO.getOrderShippingHeadDto(), headDto, logSign);
//        } catch (BusinessException e) {
//            commonResult.setCode(e.getCode());
//            commonResult.setMessage(e.getMessage());
//            logger.error("业务异常code : " + e.getCode() + ",异常信息: " + e.getMessage(),e);
//        } catch (Exception e) {
//            commonResult.setCode(ExceptionStatus.E3001001.getCode());
//            commonResult.setMessage(ExceptionStatus.E3001001.getMessage());
//            logger.error("业务异常code : " + ExceptionStatus.E3001001.getCode() + ",异常信息: " + e.getMessage(),e);
//        }
//
//        return commonResult;
//    }


    @POST
    @Path("/create/confirm")
    @Override
    public CommonResult<Integer> confirm(long code) {

        return new CommonResult<>(ReturnCode.REQUEST_SUCCESS,"ok",1);
    }
}
